package com.imageim.yimirror.ui.activity.tryCloth;

import android.graphics.Bitmap;

import com.imageim.yimirror.R;
import com.imageim.yimirror.bean.dailyPhoto.TryClothResultPhotoBean;
import com.imageim.yimirror.common.event.EventCode;
import com.imageim.yimirror.common.event.EventMessage;
import com.imageim.yimirror.ui.activity.BaseFragmentActivity;
import com.imageim.yimirror.ui.fragment.ChangePhotoBgFragment;
import com.martin.ads.omoshiroilib.util.BitmapUtils;

import org.greenrobot.eventbus.EventBus;

/**
 * 替换照片的背景，滤镜等
 * Created by Bruce.Zhou on 2018/11/22 10:12.
 * Email: 907160968@qq.com
 */
public class ChangePhotoBgActivity extends BaseFragmentActivity {
    private ChangePhotoBgFragment changePhotoBgFragment;
    public static final String NONE_BG_BITMAP = "noneBgBitmap"; // 后台去背景图
    public static final String ORIGINAL_BITMAP = "originalBitmap"; // 用户拍照裁剪后的图
    private int from; // 来自哪个页面，1来自拍照，2来自试穿留影列表
    public static final String MEM_PHOTO_BEAN = "memPhotoBean"; // 列表中的item

    @Override
    protected void initBundle() {
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_change_bg;
    }

    @Override
    protected void initView() {
        from = getIntent().getIntExtra("from", 0);
        changePhotoBgFragment = new ChangePhotoBgFragment();
        showFragmentView(changePhotoBgFragment, "changePhotoBgFragment");
        changePhotoBgFragment.setFrom(from);

        if (from == 1) {
            //        String noneBgBitmapPath = getIntent().getStringExtra(NONE_BG_BITMAP);
            String originalBitmapPath = getIntent().getStringExtra(ORIGINAL_BITMAP);
            //        Bitmap noneBgBitmap = BitmapUtils.loadBitmapFromFile(noneBgBitmapPath);
            Bitmap originalBitmap = BitmapUtils.loadBitmapFromFile(originalBitmapPath);
            changePhotoBgFragment.setBitmap(originalBitmap, null);
            changePhotoBgFragment.setOriginalBitmapLocalPath(originalBitmapPath);

            //拍照完成通知历史分析界面刷新数据
            EventBus.getDefault().post(new EventMessage(EventCode.CODE_REFRESH_HISTORY, null));
        } else if (from == 2) {
            TryClothResultPhotoBean memPhotoBean = (TryClothResultPhotoBean) getIntent().getSerializableExtra(MEM_PHOTO_BEAN);
            changePhotoBgFragment.setMemPhotoBean(memPhotoBean);
        }
    }

    @Override
    protected void initData() {

    }
}
